<?php
namespace Common\Controller;

use Common\Controller\BaseController;

/**
 * Home基类
 */
class HomeBaseController extends BaseController
{

    public function __construct()
    {
        parent::__construct();

        $this->assign('action_name', ACTION_NAME);
        $this->assign('contrller_name', CONTROLLER_NAME);
        $this->assign('module_name', MODULE_NAME);

        /*//token
        $model_user_token = Model('user_token');
        $key = $_POST['key'];
        if (empty($key)) {
            $key = $_GET['key'];
        }
        $user_token_info = $model_user_token->getMbUserTokenInfoByToken($key);
        if (empty($user_token_info)) {
            //output_error('请登录', array('login' => '0'));
            //过期的处理
            if ($user_token_info) {
                //重新登录生成新的token
            }
        }*/

    }

    /*
     * 成功返回
     */
    public function apiSuccess($param)
    {
        $ret['code'] = '200';
        $ret['data'] = $param ? $param : new \stdClass();
        die(json_encode($ret));
    }

    /*
     * 失败返回
     */
    public function apiError($param)
    {
        $ret['code'] = '400';
        $ret['data'] = $param ? $param : new \stdClass();
        die(json_encode($ret));
    }

    /*
     * param
     */
    public function ResultRi($param)
    {
        die(json_encode($param));
    }

    /**
     * 301跳转
     * @param type $url 跳转的url地址
     * @return boolean
     */
    public function header301($url)
    {
        if (empty($url)) {
            return false;
        }

        header('HTTP/1.1 301 Moved Permanently');
        header('Location:' . $url);
        exit;
    }

}

?>